<template>
  <div class="dashboard-editor-container">
    <div class="container-box">
      <div class="header">
        <span class="title">毕业去向分布情况</span>
        <YearRangePicker @get-year-range="getYearRange" class="year-picker" />
      </div>
      <div class="flex-box">
        <compare
          class="second"
          ref="myCompare1"
          :myStart="start"
          :myEnd="end"
          :key="timer"
        />
        <tabledata class="first" :myStart="start" :myEnd="end" :key="timer" />
      </div>
    </div>
  </div>
</template>

<script>
import compare from "./components/compare.vue";
import tabledata from "./components/tabledata.vue";
import mainchart from "./components/mainchart.vue";
import YearRangePicker from "../../components/yearRangePicker.vue";

export default {
  components: {
    compare,
    tabledata,
    mainchart,
    YearRangePicker,
  },
  data() {
    return {
      timer: "",
      type: 1,
      start: null,
      end: null,
    };
  },
  created() {
    this.getYears();
  },
  mounted() {
    window.onresize = () => {
      this.$refs.myCompare1.resize();
    };
  },
  methods: {
    getYears() {
      this.axios({
        url: "grad/yearList",
        methods: "get",
      }).then((res) => {
        let years = res.data.data;

        years = years.sort(function (a, b) {
          return a - b;
        });

        //默认为最近一年
        this.start = years[years.length - 1];
        this.end = years[years.length - 1];

        console.log(this.start + "      " + this.end);
      });
    },
    handleClick(tab, event) {
      //repaint the component
      this.timer = new Date().getTime();
      //get tab value
      if (tab.props.name == "first") {
        //benkesheng
        this.type = 1;
      } else {
        this.type = 2;
      }
    },
    getYearRange(start, end) {
      this.timer = new Date().getTime();
      this.start = start;
      this.end = end;
    },
  },
};
</script>

<style scoped>
.dashboard-editor-container {
  background-color: rgb(240, 242, 245);
  position: relative;
  display: flex;
  flex-wrap: nowrap;
  justify-content: space-betwen;
}

.container-box {
  width: 100%;
  margin: 0 auto;
  background: #fff;
  padding-bottom: 100px;
  padding-top: 30px;
}

.header {
  width: 80%;
  margin: 0 auto;
  display: -webkit-flex; /* Safari */
  display: flex;
  flex-direction: row; /* 水平方向 */
  flex-wrap: wrap; /* 超出换行 */
  justify-content: space-between;
}

.title {
  padding-top: 20px;
  font-size: 32px;
  color: black;
  font-weight: 600;
}

.year-picker {
  width: 300px;
  margin-top: 18px;
  display: inline-block;
}

.flex-box {
  width: 90%;
  margin: 0 auto;
  display: -webkit-flex; /* Safari */
  display: flex;
  flex-direction: row; /* 水平方向 */
  flex-wrap: wrap; /* 超出换行 */
  justify-content: space-between;
}

.first {
  padding-top: 60px;
  width: 49%;
}

.second {
  width: 49%;
}

@media (max-width: 1300px) {
  .first {
    width: 100%;
  }

  .second {
    width: 100%;
  }
}
</style>
